{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('admin/want_buy/index')}">求购管理</a></li>
            <li class="layui-this">添加求购</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form form-container" action="{:url('admin/want_buy/save')}" method="post">
                    <div class="layui-form-item">
                        <label class="layui-form-label">内容</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入求购内容" class="layui-textarea" name="content"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">图集</label>
                        <div class="layui-input-block" id="div-photo">
                            <input type="text" name="photos[]" id="photo1" placeholder="（选填）请输入图片url" class="layui-input">
                        </div>
                        <div class="layui-input-block">
                            <a  class="layui-btn" href="javascript:void(0)" onclick="add_photo()">+</a>
                            <a  class="layui-btn" href="javascript:void(0)" onclick="del_photo()">-</a>
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">选择作者</label>
                        <div class="layui-input-block">
                            <select name="uid" lay-verify="required">
                                {foreach name="author_list" item="aut"}
                                <option value="{$aut.uid}">{$aut.nickname}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">经度</label>
                        <div class="layui-input-block">
                            <input type="text" name="lon" placeholder="（选填）输入经度"   class="layui-input layui-input-inline">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">维度</label>
                        <div class="layui-input-block">
                            <input type="text" name="lat"  placeholder="（选填）输入维度"  class="layui-input layui-input-inline">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">地点</label>
                        <div class="layui-input-block">
                            <input type="text" name="location" placeholder="（选填）输入地点"   class="layui-input layui-input-inline">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="*">保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script>
    var photo_id = 1;
    function add_photo(){
        photo_id  = photo_id +1;
        var div_select = "<input type='text' name='photos[]' id='photo"+photo_id+"' placeholder='（选填）请输入图片url' class='layui-input'>";
        $('#div-photo').append(div_select);
    }
    function del_photo() {
        if(photo_id<2){
            alert('已经是最后一个了没法删除了');
            return false;
        }
        $('#photo'+photo_id).remove();
        photo_id  = photo_id -1;
    }
</script>
{/block}
